import { TypeOrmModuleOptions } from '@nestjs/typeorm';
import { join } from 'path';
// 显式导入process，解决IDE警告
import * as process from 'process';

/**
 * 数据库配置
 * @returns TypeORM配置选项
 */
export const databaseConfig = (): TypeOrmModuleOptions => ({
  type: 'mysql',
  host: process.env.DB_HOST || 'localhost',
  port: parseInt(process.env.DB_PORT || '3306', 10),
  username: process.env.DB_USERNAME || 'root',
  password: process.env.DB_PASSWORD || '289244',
  database: process.env.DB_DATABASE || 'nest_app',
  entities: [join(__dirname, '..', 'modules', '**', 'entities', '*.entity.{ts,js}')],
  synchronize: process.env.NODE_ENV !== 'production', // 自动同步数据库结构，生产环境中应该禁用
  logging: process.env.NODE_ENV !== 'production',
});
 